---@diagnostic disable: trailing-space
local extension = Package:new("moepack_moon")
extension.extensionName = "moepack"

Fk:loadTranslationTable{
  ["moepack_moon"] = "萌包-皎月",
}

local U = require "packages/utility/utility"
local MoeFunc = require "packages/moepack/moepack_function"

local moe__jingzi = General(extension, "moe__jingzi", "moe", 4, 4, General.Female)

local emo__tianchen = fk.CreateViewAsSkill{
  name = "emo__tianchen",
  pattern = "fire__slash,thunder__slash",
  prompt = "emo__tianchen-prompt",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type ~= Card.TypeBasic
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local name = Fk:getCardById(cards[1]).type == Card.TypeTrick and "fire__slash" or "thunder__slash"
    local card = Fk:cloneCard(name)
    card:addSubcard(cards[1])
    card.skillName = self.name
    return card
  end,
  before_use = function (self, player, use)
    use.extra_data = use.extra_data or {}
    use.extra_data.emo__tianchen_user = player.id
    if use.card.name == "fire__slash" then
      use.additionalEffect = (use.additionalEffect or 0) + 1
    end
  end,
  enabled_at_response = function(self, player, response)
    return not response
  end,
}

local emo__tianchen_targetmod = fk.CreateTargetModSkill{
  name = "#emo__tianchen_targetmod",
  extra_target_func = function(self, player, skill, card)
    if card and card.name == "thunder__slash" and table.contains(card.skillNames, "emo__tianchen")  then
      return 1
    end
  end,
}
emo__tianchen:addRelatedSkill(emo__tianchen_targetmod)

local emo__tianchen_trigger = fk.CreateTriggerSkill{
  name = "#emo__tianchen_trigger",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if not player.dead and data.card and player:distanceTo(data.to) == 1 then
      local e = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
      if e then
        local use = e.data[1]
        return player.id == (use.extra_data or {}).emo__tianchen_user
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, 1)
    if not player.dead then
      player:drawCards(player:getLostHp(), self.name)
    end
  end,
}
emo__tianchen:addRelatedSkill(emo__tianchen_trigger)

moe__jingzi:addSkill(emo__tianchen)

Fk:loadTranslationTable{
  ["moe__jingzi"] = "倞子",

  ["emo__tianchen"] = "天嗔",
  [":emo__tianchen"] = "你可以：1.将一张锦囊牌当额外结算一次的火【杀】使用；2.将一张装备牌当目标上限+1的雷【杀】使用。此【杀】对你距离为1的角色造成伤害后，你增加1点体力上限并摸等于已损失体力值的牌。",
  ["#emo__tianchen_trigger"] = "天嗔",
  ["emo__tianchen-prompt"] = "将锦囊牌当额外结算一次的火【杀】使用；或将装备牌当目标上限+1的雷【杀】使用",
}

local moe__yezi = General(extension, "moe__yezi", "moe", 3, 3, General.Female)

local emo__luoai = fk.CreateTriggerSkill{
  name = "emo__luoai",
  anim_type = "drawcard",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target.phase > 1 and target.phase < 8 and #player.room.discard_pile > 0 then
      local n = 0
      player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.toArea == Card.DiscardPile and move.moveReason ~= fk.ReasonUse and move.moveReason ~= fk.ReasonResonpse then
            n = n + #move.moveInfo
          end
        end
        return false
      end, Player.HistoryPhase)
      return n >= 2
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:obtainCard(player, room.discard_pile[1], true, fk.ReasonPrey)
  end,
}

moe__yezi:addSkill(emo__luoai)

local emo__huahuo = fk.CreateActiveSkill{
  name = "emo__huahuo",
  anim_type = "drawcard",
  card_num = 1,
  min_target_num = 1,
  max_target_num = 3,
  target_filter = function(self, to_select, selected)
    return #selected < (3 - Self:getMark("emo__huahuo_used-phase"))
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 3 and player:getMark("emo__huahuo_used-phase") < 3
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, player, player)
    room:addPlayerMark(player, "emo__huahuo_used-phase")
    local card = Fk:getCardById(effect.cards[1])
    local cards = room:getCardsFromPileByRule(".|.|"..card:getSuitString(), #effect.tos)
    if #cards == 0 then return end
    room:moveCards({ ids = cards, toArea = Card.Processing, moveReason = fk.ReasonPut })
    local tos = table.map(effect.tos, Util.Id2PlayerMapper)
    table.forEach(room.players, function(p) room:fillAG(p, cards) end)
    for _, to in ipairs(tos) do
      if #cards == 0 then break end
      if to:isAlive() then
        local chosen = room:askForAG(to, cards, false, self.name)
        room:takeAG(to, chosen, room.players)
        room:obtainCard(to, chosen, true, fk.ReasonPrey)
        table.removeOne(cards, chosen)
      end
    end
    room:delay(1000)
    table.forEach(room.players, function(p) room:closeAG(p) end)

    local toDiscard = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
    if #toDiscard > 0 then
      room:moveCards({
        ids = toDiscard,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonPutIntoDiscardPile,
      })
    end
  end,
}

moe__yezi:addSkill(emo__huahuo)


Fk:loadTranslationTable{
  ["moe__yezi"] = "叶子",

  ["emo__luoai"] = "落哀",
  [":emo__luoai"] = "任何阶段结束时，若此阶段内至少有两张牌不因使用或打出而进入弃牌堆，你可以获得最早进入弃牌堆的一张牌。",
  
  ["emo__huahuo"] = "花火",
  [":emo__huahuo"] = "出牌阶段限三次，你可以弃置一张牌并指定至多三名角色，亮出牌堆中等量张与你弃置的牌同花色的牌，你指定的角色依次挑选并获得其中一张牌，然后本阶段中此技能目标上限减1。",
}


local moe__shuizhilai = General(extension, "moe__shuizhilai", "moe", 3, 3, General.Female)

local emo__moyin = fk.CreateTriggerSkill{
  name = "emo__moyin",
  events = {fk.CardUseFinished, fk.CardRespondFinished, fk.AfterCardsMove},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    local num
    if event == fk.AfterCardsMove then
      local ret = {}
      for _, move in ipairs(data) do
        if move.toArea == Card.PlayerHand and move.to == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.DrawPile then
              table.insert(ret, info.cardId)
            end
          end
        elseif move.from == player.id and move.moveReason == fk.ReasonDiscard then
          for _, info in ipairs(move.moveInfo) do
            if (info.fromArea == Card.PlayerEquip) or (info.fromArea == Card.PlayerHand) then
              table.insert(ret, info.cardId)
            end
          end
        end
      end
      if #ret ~= 1 then return false end
      num = Fk:getCardById(ret[1]).number
    elseif target == player then
      num = data.card.number
    end
    if num then
      self.cost_data = num
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("@emo__moyin")
    table.insert(mark, self.cost_data)
    if #mark > 3 then
      table.remove(mark, 1)
    end
    room:setPlayerMark(player, "@emo__moyin", mark)
    local max, min = math.max(table.unpack(mark)), math.min(table.unpack(mark))
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|0~"..(min-1)..","..(max+1).."~999",
      skipDrop = true,
    }
    room:judge(judge)
    if judge.card:matchPattern(judge.pattern) then
      if not player.dead and room:getCardArea(judge.card) == Card.Processing then
        room:obtainCard(player, judge.card, true, fk.ReasonPrey, player.id, self.name)
      end
    else
      if #room:askForDiscard(player, 1, 1, true, self.name, true, ".", "#emo__moyin-discard") == 0 then
        room:invalidateSkill(player, self.name, "-turn")
      end
    end
    if room:getCardArea(judge.card) == Card.Processing then
      room:moveCardTo(judge.card, Card.DiscardPile, nil, fk.ReasonJudge)
    end
  end,

  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@emo__moyin", 0)
  end,
}
moe__shuizhilai:addSkill(emo__moyin)

local emo__chanlie = fk.CreateTriggerSkill{
  name = "emo__chanlie",
  anim_type = "masochism",
  frequency = Skill.Compulsory,
  events = {fk.Damaged},
  on_use = function(self, event, target, player, data)
    local room = player.room
    local nums = player:getTableMark("@emo__moyin")
    room:setPlayerMark(player, "@emo__moyin", 0)
    local get = {}
    if #nums > 0 then
      local pile = table.simpleClone(room.discard_pile)
      while #nums > 0 do
        local id = table.remove(pile, math.random(#pile))
        if table.removeOne(nums, Fk:getCardById(id).number) then
          table.insert(get, id)
        end
      end
    end
    room:delay(200)
    if #get > 0 then
      room:moveCardTo(get, Player.Hand, player, fk.ReasonPrey, self.name, nil, true, player.id)
    else
      local cur = room.current
      if cur and cur:isAlive() then
        room:doIndicate(player.id, {cur.id})
        room:loseHp(cur, 1, self.name)
      end
    end
  end,
}
moe__shuizhilai:addSkill(emo__chanlie)

Fk:loadTranslationTable{
  ["moe__shuizhilai"] = "水凪濑",
  ["#moe__shuizhilai"] = "律动人间",

  ["emo__moyin"] = "魔音",
  [":emo__moyin"] = "锁定技，每当你使用、打出、摸、弃置一张牌后，你记录此牌点数，然后进行判定，若判定牌点数比最近三次点数记录均大或均小，你获得之，否则，你须弃置一张牌，或令本回合〖魔音〗失效。",
  ["@emo__moyin"] = "魔音",
  ["#emo__moyin-discard"] = "魔音：你须弃置一张牌，否则本回合〖魔音〗失效",

  ["emo__chanlie"] = "颤裂",
  [":emo__chanlie"] = "锁定技，当你受到伤害后，你清空“魔音”的记录，并从弃牌堆获得对应点数的牌各一张，若未获得牌，令当前回合者失去1点体力。",
}

local moe__zhuqukui = General(extension, "moe__zhuqukui", "moe", 3, 3, General.Female)

local emo__shenzhu = fk.CreateTriggerSkill{
  name = "emo__shenzhu",
  anim_type = "defensive",
  events = {fk.TurnEnd, fk.Damaged, fk.TurnStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.TurnStart and player:getMark("@emo__blessing") <= player.hp then return false end
    return player == target and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      local n = player:getMark("@emo__blessing")
      room:setPlayerMark(player, "@emo__blessing", player.hp)
      room:recover { num = n - player.hp, skillName = self.name, who = player , recoverBy = player }
    else
      room:addPlayerMark(player, "@emo__blessing")
      player:drawCards(1, self.name)
      if not player.dead then
        room:changeMaxHp(player, 1)
      end
    end
  end,
}
moe__zhuqukui:addSkill(emo__shenzhu)


local emo__quchen = fk.CreateActiveSkill{
  name = "emo__quchen",
  anim_type = "support",
  can_use = function(self, player)
    return player.maxHp > player.hp
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 1,
  prompt = "#emo__quchen",
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local x = player.maxHp - to.maxHp
    room:changeMaxHp(player, -x)
    if not to.dead then
      to:drawCards(x, self.name)
      to:reset()
    end
  end,
}
moe__zhuqukui:addSkill(emo__quchen)

Fk:loadTranslationTable{
  ["moe__zhuqukui"] = "竹取葵",
  ["#moe__zhuqukui"] = "祭山巫女",
  
  ["emo__shenzhu"] = "神祝",
  [":emo__shenzhu"] = "锁定技，每当你受到伤害后或你回合结束时，你获得1枚“祝”标记，摸一张牌，增加1点体力上限。回合开始时，若你的“祝”标记大于体力值，你交换“祝”标记数与体力值。",
  ["@emo__blessing"] = "祝",

  ["emo__quchen"] = "祛尘",
  ["#emo__quchen"] = "将体力上限扣减至体力值，令一名其他角色摸等量张牌并复原武将牌",
  [":emo__quchen"] = "出牌阶段，你可以将体力上限扣减至体力值，令一名其他角色摸等量张牌并复原武将牌。",
}

local moe__mucunshiyu = General(extension, "moe__mucunshiyu", "moe", 3, 3, General.Female)

local emo__jieyuan = fk.CreateActiveSkill{
  name = "emo__jieyuan",
  anim_type = "control",
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 2,
  target_filter = function(self, to_select, selected)
    if #selected == 0 then 
      return true
    elseif #selected == 1 then
      local to1 = Fk:currentRoom():getPlayerById(selected[1])
      local to2 = Fk:currentRoom():getPlayerById(to_select)
      return to1.kingdom == "moe" or to2.kingdom == "moe" or to1.gender ~= to2.gender
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to1 = room:getPlayerById(effect.tos[1])
    local to2 = room:getPlayerById(effect.tos[2])
    local x = to1.maxHp - to2.maxHp
    if x > 0 then
      room:changeMaxHp(to2, math.min(2, x))
    elseif x < 0 then
      room:changeMaxHp(to1, math.min(2, -x))
    end
    local y = to1.hp - to2.hp
    if y > 0 then
      room:recover({ who = to2, num = math.min(2, y), recoverBy = player, skillName = self.name  })
    elseif y < 0 then
      room:recover({ who = to1, num = math.min(2, -y), recoverBy = player, skillName = self.name  })
    end
    if table.every(room.alive_players, function (p) return not p:hasSkill("emo__yuanding", true) end) then
      room:handleAddLoseSkills(to1, "emo__yuanding")
      room:handleAddLoseSkills(to2, "emo__yuanding")
    end
  end,
}
moe__mucunshiyu:addSkill(emo__jieyuan)

local emo__yuanding = fk.CreateTriggerSkill{
  name = "emo__yuanding",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart, fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Play and
      #table.filter(player.room:getOtherPlayers(player), function(p)
        return p:hasSkill(self, true)
      end) == 1
    else
      return target == player and player:hasSkill(self) and data.to:hasSkill(self) and player ~= data.to
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local to = table.find(player.room:getOtherPlayers(player), function(p)
        return p:hasSkill(self, true)
      end)
      if not to then return false end
      room:doIndicate(player.id, {to.id})
      if not to:isKongcheng() then
        U.viewCards(player, to:getCardIds(Player.Hand), self.name, "$ViewCardsFrom:"..to.id)
      end
      local lowerHp = math.min(player.hp, to.hp)
      local higherHp = math.max(player.hp, to.hp)
      local to_recover = table.filter({player,to},function (p)return p.hp == lowerHp end)
      local to_draw = table.filter({player,to},function (p)return p.hp == higherHp end)
      for _, p in ipairs(to_recover) do
        if p:isWounded() and not p.dead then
          room:recover({ who = p, num = 1, recoverBy = player, skillName = self.name,  })
        end
      end
      for _, p in ipairs(to_draw) do
        if not p.dead then
          p:drawCards(2, self.name)
        end
      end
    else
      local choice = room:askForChoice(player, {"emo__yuanding_prevent", "emo__yuanding_loseskill"}, self.name, "#emo__yuanding_damage:"..data.to.id)
      if choice == "emo__yuanding_prevent" then
        return true
      else
        room:handleAddLoseSkills(player, "-emo__yuanding")
        room:handleAddLoseSkills(data.to, "-emo__yuanding")
      end
    end
  end,
}
moe__mucunshiyu:addRelatedSkill(emo__yuanding)

local emo__lihen = fk.CreateTriggerSkill{
  name = "emo__lihen",
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self, false, true)
  end,
  on_cost = function (self, event, target, player, data)
    local tos = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 999, "#emo__lihen-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, pid in ipairs(self.cost_data) do
      room:setPlayerMark(room:getPlayerById(pid), "@@emo__lihen", 1)
    end
  end,
}

local emo__lihen_delay = fk.CreateTriggerSkill{
  name = "#emo__lihen_delay",
  events = {fk.EventPhaseStart},
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return target == player and target.phase == Player.Play and player:getMark("@@emo__lihen") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@emo__lihen", 0)
    local cards,map = {},{}
    for _, id in ipairs(target:getCardIds("he")) do
      if not target:prohibitDiscard(Fk:getCardById(id)) then
        local t = Fk:getCardById(id).type
        map[t] = map[t] or {}
        table.insert(map[t], id)
      end
    end
    for _, c in pairs(map) do
      table.insert(cards, table.random(c))
    end
    if #cards > 0 then
      room:throwCard(cards, emo__lihen.name, target, target)
    end
    if not target.dead and #cards < 3 then
      room:loseHp(target, 1, emo__lihen.name)
    end
  end,
}
emo__lihen:addRelatedSkill(emo__lihen_delay)

moe__mucunshiyu:addSkill(emo__lihen)

Fk:loadTranslationTable{
  ["moe__mucunshiyu"] = "木村时雨",

  ["emo__jieyuan"] = "结缘",
  [":emo__jieyuan"] = "限定技，出牌阶段，你可以指定两名异性角色（萌势力角色不限性别），这两名角色将体力上限、体力值均调整为两角色中的较大值（每项至多增加2点），然后若没有存活角色拥有〖缘定〗，令这两名角色获得〖缘定〗。",

  ["emo__yuanding"] = "缘定",
  [":emo__yuanding"] = "锁定技，①出牌阶段开始时，你观看拥有“缘定”的其他角色的手牌，然后你与其体力值较小的一方回复1点体力，体力值较大的一方摸两张牌，体力值相同则双方均执行两个效果。<br>"..
  "②你对拥有“缘定”的其他角色造成伤害时，须选择防止此伤害，或令你与其失去“缘定”。",

  ["emo__yuanding_prevent"] = "防止对其造成伤害",
  ["emo__yuanding_loseskill"] = "令你与其失去“缘定”",
  ["#emo__yuanding_damage"] = "缘定：防止对 %src 造成伤害，或令你与其失去“缘定”",

  ["emo__lihen"] = "离恨",
  [":emo__lihen"] = "当你死亡时，你可以选择任意名角色，这些角色的下个出牌阶段开始时，令其随机弃置每种类型各一张牌，若弃置牌数小于3，其失去一点体力。",
  ["#emo__lihen-choose"] = "离恨：你可选择任意名角色，其下个出牌阶段随机弃置每种类型各一张牌",
  ["@@emo__lihen"] = "离恨",
  ["#emo__lihen_delay"] = "离恨",

  ["$emo__jieyuan1"] = "结发为夫妻，恩爱两不疑",
  ["$emo__jieyuan2"] = "陌上人如玉，公子世无双",
  ["$emo__lihen1"] = "白首望关，不见君归",
  ["$emo__lihen2"] = "天长地久有时尽，此恨绵绵无绝期",
}

local moe__gaoqiaozhenxi = General(extension, "moe__gaoqiaozhenxi", "moe", 3, 3, General.Female)

local emo__liqun = fk.CreateTriggerSkill{
  name = "emo__liqun",
  anim_type = "drawcard",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    -- 获取本轮进入过回合的角色
    local in_turn = table.filter(room.alive_players, function (p) 
      return #player.room.logic:getEventsOfScope(GameEvent.Turn, 1, function (e) return e.data[1] == p end, Player.HistoryRound) > 0 
    end)
    local all_choices = {"emo__liqun_1", "emo__liqun_2", "emo__liqun_3", "Cancel"}
    local choices = table.simpleClone(all_choices)
    if table.contains(in_turn, player) or table.contains(in_turn, player:getLastAlive(true)) then
      table.removeOne(choices, "emo__liqun_1")
    end
    if table.contains(in_turn, player) or table.contains(in_turn, player:getNextAlive(true)) then
      table.removeOne(choices, "emo__liqun_2")
    end
    local targets = table.filter(in_turn, function (p) return not p:isNude() and p ~= player end)
    if #targets == 0 then
      table.removeOne(choices, "emo__liqun_3")
    end
    local choice = room:askForChoice(player, choices, self.name, nil, false, all_choices)
    if choice ~= "Cancel" then
      self.cost_data = choice
      if choice == "emo__liqun_3" then
        self.cost_data = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1,
        "#emo__liqun-choose", self.name, false)[1]
      end
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if self.cost_data == "emo__liqun_1" then
      local to = player:getLastAlive(true)
      to:drawCards(2, self.name)
      room:swapSeat(to, player)
    elseif self.cost_data == "emo__liqun_2" then
      local to = player:getNextAlive(true)
      player:drawCards(2, self.name)
      room:swapSeat(to, player)
    else
      local id = room:askForCardChosen(player, room:getPlayerById(self.cost_data), "he", self.name)
      room:obtainCard(player, id, false, fk.ReasonPrey)
    end
  end,
}
moe__gaoqiaozhenxi:addSkill(emo__liqun)

local emo__zanghua = fk.CreateTriggerSkill{
  name = "emo__zanghua",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.to ~= player.id
    and (data.card.trueName == "slash" or data.card.trueName == "peach") then
      local to = player.room:getPlayerById(data.to)
      if to.dead then return end
      local hasDead = false
      local temp = player.next
      while temp ~= to do
        hasDead = temp.dead
        if not hasDead then break end
        temp = temp.next
      end
      if hasDead then return true end
      temp = to.next
      while temp ~= player do
        hasDead = temp.dead
        if not hasDead then break end
        temp = temp.next
      end
      return hasDead
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    if data.card.trueName == "slash" then
      room:addPlayerMark(to, MarkEnum.UncompulsoryInvalidity .. "-turn")
      data.additionalDamage = (data.additionalDamage or 0) + 1
    else
      room:setPlayerMark(room:getPlayerById(data.to), "@@emo__zanghua-turn", 1)
      data.additionalRecover = (data.additionalRecover or 0) + 1
    end
  end,
}
local emo__zanghua_prohibit = fk.CreateProhibitSkill{
  name = "#emo__zanghua_prohibit",
  is_prohibited = function(self, from, to, card)
    return card and card.is_damage_card and to and to:getMark("@@emo__zanghua-turn") > 0
  end,
}
emo__zanghua:addRelatedSkill(emo__zanghua_prohibit)

moe__gaoqiaozhenxi:addSkill(emo__zanghua)

Fk:loadTranslationTable{
  ["moe__gaoqiaozhenxi"] = "高桥真希",

  ["emo__liqun"] = "离群",
  [":emo__liqun"] = "每当你受到伤害后，你可以选一项：1.若你与上家本轮未进入回合，你可以令其摸两张牌并与其交换座位；2.若你与下家本轮未进入回合，你可以摸两张牌并与其交换座位；3.你获得本轮已进入回合的一名其他角色的一张牌。",
  ["emo__liqun_1"] = "令上家摸两张牌并与其交换座位",
  ["emo__liqun_2"] = "摸两张牌并与下家交换座位",
  ["emo__liqun_3"] = "获得已进入回合的其他角色的一张牌",
  ["#emo__liqun-choose"] = "离群：获得已进入回合的其他角色的一张牌",

  ["emo__zanghua"] = "葬花",
  [":emo__zanghua"] = "锁定技，每当你使用【杀】/【桃】指定目标后，若你至该目标角色的任意路径之间均为死亡角色，你令其本回合非锁定技失效且此【杀】伤害值+1/其本回合不为伤害牌的目标且此【桃】回复值+1。",
  ["@@emo__zanghua-turn"] = "葬花:守护",
}

local moe__zhishi = General(extension, "moe__zhishi", "moe", 3, 3, General.Female)

local emo__fuhun = fk.CreateTriggerSkill{
  name = "emo__fuhun",
  anim_type = "control",
  events = {fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#emo__fuhun-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = tos[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askForChoice(player, {"emo__fuhun_red" , "emo__fuhun_black"}, self.name)
    local to = room:getPlayerById(self.cost_data)
    if choice == "emo__fuhun_red" then
      room:setPlayerMark(to, "@emo__fuhun-round", "jink")
      local cards = room:getCardsFromPileByRule(".|.|heart,diamond", 2)
      if #cards > 0 then
        room:moveCards({
          ids = cards,
          to = to.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonPrey,
          skillName = self.name,
          moveVisible = false,
          proposer = player.id,
        })
      end
    else
      room:setPlayerMark(to, "@emo__fuhun-round", "slash")
      room:askForDiscard(to, 2, 2, true, self.name, false, ".|.|spade,club")
    end
  end,
}

local emo__fuhun_delay = fk.CreateTriggerSkill{
  name = "#emo__fuhun_delay",
  mute = true,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    local mark = player:getMark("@emo__fuhun-round")
    if target == player and not player.dead and mark ~= 0 then
      return data.card.trueName == mark and not (mark == "slash" and player:isKongcheng())
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.card.trueName == "jink" then
      target:drawCards(1, "emo__fuhun")
    else
      room:askForDiscard(target, 1, 1, false, "emo__fuhun", false)
    end
  end,
}
emo__fuhun:addRelatedSkill(emo__fuhun_delay)

moe__zhishi:addSkill(emo__fuhun)

local emo__lixin = fk.CreateTriggerSkill{
  name = "emo__lixin",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused , fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and data.from and target == player and data.card and data.card.type == Card.TypeTrick then
      if event == fk.DamageCaused then
        return data.to.gender == General.Male or data.to.gender == General.Bigender
      else
        return data.from.gender == General.Female or data.from.gender == General.Bigender
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.DamageCaused then
      data.damage = data.damage + 1
    else
      data.damage = data.damage - 1
    end
  end,
}
moe__zhishi:addSkill(emo__lixin)

local emo__anchong = fk.CreateTriggerSkill{
  name = "emo__anchong",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.GameStart , fk.AskForPeachesDone},
  can_trigger = function(self, event, target, player, data)
    if event == fk.GameStart then
      return player:hasSkill(self) and type(player:getMark(self.name)) ~= "string"
    else
      return player:hasSkill(self) and target == player and not data.ignoreDeath and player.dying
      and type(player:getMark(self.name)) == "string"
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      local generalPile = {}
      for _, name in pairs(room.general_pile) do
        local general = Fk.generals[name]
        if general.gender == General.Female and general.maxHp == 3 then
          table.insert(generalPile, name)
        end
      end
      if #generalPile == 0 then return false end
      local generals = table.random(generalPile, 5)
      local name = room:askForGeneral(player, generals, 1, true)
      room:setPlayerMark(player, self.name, name)
    else
      local name = player:getMark(self.name)
      room:setPlayerMark(player, self.name, 0)
      data.ignoreDeath = true
      room:setPlayerProperty(player, "dying", false)
      room:setPlayerProperty(player, "maxHp", 3)
      room:setPlayerProperty(player, "hp", 3)

      local skills = {}
      local newGeneral = Fk.generals[name]
      for _, skill in ipairs(player.player_skills) do
        if skill.frequency ~= Skill.Compulsory then
          table.insert(skills, "-"..skill.name)
        end
      end
      for _, n in ipairs(newGeneral:getSkillNameList()) do
        local s = Fk.skills[n]
        if (not s.relate_to_place or s.relate_to_place == "m") and
        (#s.attachedKingdom == 0 or table.contains(s.attachedKingdom, newGeneral.kingdom)) then
          table.insertIfNeed(skills, n)
        end
      end
      room:changeKingdom(player, newGeneral.kingdom)
      room:sendLog{
        type = "#ChangeHero",
        from = player.id,
        arg = player.general,
        arg2 = name,
        arg3 = "mainGeneral",
      }
      room:setPlayerProperty(player, "general", name)
      room:handleAddLoseSkills(player, table.concat(skills, "|"))
    end
  end,
}
moe__zhishi:addSkill(emo__anchong)

Fk:loadTranslationTable{
  ["moe__zhishi"] = "知世",
  
  ["emo__fuhun"] = "缚魂",
  [":emo__fuhun"] = "每轮开始时，你可以指定一名角色并选一项：①令其摸两张红色牌，其本轮使用【闪】时摸一张牌。②令其弃置两张黑色牌，其本轮使用【杀】时弃置一张手牌。",
  ["emo__fuhun_delay"] = "缚魂",
  ["#emo__fuhun-choose"] = "缚魂：选择一名角色，令其摸两张红色牌或弃置两张黑色牌",
  ["emo__fuhun_red"] = "摸两张红色牌",
  ["emo__fuhun_black"] = "弃两张黑色牌",
  ["@emo__fuhun-round"] = "缚魂",

  ["emo__lixin"] = "离心",
  [":emo__lixin"] = "锁定技，你受到女性角色造成的锦囊伤害-1，你对男性角色造成的锦囊伤害+1。",

  ["emo__anchong"] = "暗宠",
  [":emo__anchong"] = "锁定技，游戏开始时，你从五张体力上限为3的女性武将中选择一个。你的濒死状态结算后，若你仍处于濒死状态，你失去所有非锁定技，将体力上限和体力值调整为3，将你的主将替换为选择的武将。",
}

local moe__fengyu = General(extension, "moe__fengyu", "moe", 8, 8, General.Female)

local emo__weikui = fk.CreateTriggerSkill{
  name = "emo__weikui",
  events = {fk.CardUseFinished},
  anim_type = "switch",
  switch_skill_name = "emo__weikui",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if player:getSwitchSkillState(self.name) == fk.SwitchYang then
        return data.card.color == Card.Black
      else
        return data.card.color == Card.Red
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local isYang = player:getSwitchSkillState(self.name, true) == fk.SwitchYang
    if isYang then
      room:loseHp(player, 1, self.name)
    else
      room:changeMaxHp(player, -1)
    end
    if player.dead then return end
    local suits = isYang and "diamond,heart" or "spade,club"
    local ids = room:getCardsFromPileByRule(".|.|"..suits, 1, "allPiles")
    if #ids > 0 then
      room:obtainCard(player, ids, true, fk.ReasonJustMove, player.id, self.name)
    end
  end,
}
moe__fengyu:addSkill(emo__weikui)

Fk:loadTranslationTable{
  ["moe__fengyu"] = "枫语",

  ["emo__weikui"] = "危溃",
  [":emo__weikui"] = "锁定技，转换技，阳：当你使用黑色牌后，失去1点体力并获得一张红色牌；阴：当你使用红色牌后，扣减1点体力上限并获得一张黑色牌。",
}

local moe__xinyueli = General(extension, "moe__xinyueli", "moe", 6, 6, General.Female)

local emo__baogui = fk.CreateTriggerSkill{
  name = "emo__baogui",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused , fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and not player:isWounded() and data.card and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end
}

local emo__baogui_tm = fk.CreateTargetModSkill{
  name = "#emo__baogui_tm",
  residue_func = function(self, player, skill, scope, card)
    if skill and scope and skill.trueName == "slash_skill" and scope == Player.HistoryPhase 
    and table.find(Fk:currentRoom().alive_players, function (p) return p:hasSkill("emo__baogui") end) then
      return 1
    end
  end,
}
emo__baogui:addRelatedSkill(emo__baogui_tm)

moe__xinyueli:addSkill(emo__baogui)

local emo__liehou = fk.CreateTriggerSkill{
  name = "emo__liehou",
  events = {fk.EventPhaseStart},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play and player:isWounded() 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = player.maxHp - player.hp
    room:changeMaxHp(player, -n)
    if player.hp <= 3 then n = 2 * n end
    player:drawCards(n, self.name)
  end,
}
moe__xinyueli:addSkill(emo__liehou)


Fk:loadTranslationTable{
  ["moe__xinyueli"] = "心月礼",

  ["emo__baogui"] = "暴鬼",
  [":emo__baogui"] = "锁定技，若你存活，所有角色使用【杀】次数+1。若你未受伤，你使用和受到【杀】造成的伤害+1。",

  ["emo__liehou"] = "裂喉",
  [":emo__liehou"] = "锁定技，出牌阶段开始时，若你已受伤，你扣减体力上限至体力值，并摸数量等同于扣减数的牌，若体力值不大于3，改为摸双倍的牌。",
}
local moe__huagurou = General(extension, "moe__huagurou", "moe", 6, 6, General.Female)

local emo__yugui = fk.CreateTriggerSkill{
  name = "emo__yugui",
  anim_type = "negative",
  events = {fk.TargetConfirmed, fk.Damaged},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.TargetConfirmed then
      return target == player and player:hasSkill(self) and data.card.trueName == "slash" and 
      player.room:getPlayerById(data.from).gender == General.Male
    else
      return target == player and player:hasSkill(self) and data.from and data.from.gender == General.Male 
      and data.from ~= player and not data.from.dead
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirmed then
      data.disresponsiveList = data.disresponsiveList or {}
      table.insertIfNeed(data.disresponsiveList, player.id)
    else
      local n = 0
      player.room.logic:getActualDamageEvents(1, function(e)
        if e.data[1].to == player then
          n = n + e.data[1].damage
        end
      end)
      local from = data.from
      local use = room:askForUseCard(from, "slash", "slash", "#emo__yugui-slash::"..player.id..":"..n, true, 
      {exclusive_targets = {player.id} , bypass_distances = true, bypass_times = true })
      if use then
        use.extraUse = true
        room:useCard(use)
      elseif not player.dead and not from:isAllNude() and n > 0 then
        local cards = from:getCardIds("hej")
        if #cards > n then
          cards = room:askForCardsChosen(player, from, n, n, "hej", self.name)
        end
        room:obtainCard(player, cards, false, fk.ReasonPrey)
      end
    end
  end,
}
moe__huagurou:addSkill(emo__yugui)

local emo__huagu = fk.CreateTriggerSkill{
  name = "emo__huagu",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    local to = data.to
    return player:hasSkill(self) and target == player and player ~= to and player:isWounded() and to:isWounded() and not to.dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.to
    room:changeMaxHp(player, -1)
    room:changeMaxHp(to, -1)
    if player:isWounded() and not player.dead then
      room:recover({ who = player,  num = 1, skillName = self.name, recoverBy = player })
    end
  end,
}
moe__huagurou:addSkill(emo__huagu)


Fk:loadTranslationTable{
  ["moe__huagurou"] = "画骨柔",

  ["emo__yugui"] = "欲鬼",
  [":emo__yugui"] = "锁定技，你无法响应男性角色使用的【杀】。每当你受到其他男性角色造成的伤害后，其须对你使用一张【杀】，否则你获得其区域内X张牌（X为本回合你累计受到的伤害数）。",
  ["#emo__yugui-slash"] = "欲鬼：你须对 %dest 使用一张【杀】，否则其获得你区域内 %arg 张牌",

  ["emo__huagu"] = "化骨",
  [":emo__huagu"] = "锁定技，每当你对一名其他角色造成伤害后，若你与其均已受伤，则你与其各扣减1点体力上限，然后你回复一点体力。",
}

local moe__zidongying = General(extension, "moe__zidongying", "moe", 6, 6, General.Female)

local emo__huagui = fk.CreateMaxCardsSkill{
  name = "emo__huagui",
  frequency = Skill.Compulsory,
  fixed_func = function(self, player)
    if player:hasSkill(self) then
      return player:getLostHp()
    end
  end
}

moe__zidongying:addSkill(emo__huagui)


local emo__yankui = fk.CreateTriggerSkill{
  name = "emo__yankui",
  anim_type = "offensive",
  events = {fk.EventPhaseEnd},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Discard
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = 0
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.toArea == Card.DiscardPile then
          n = n + #move.moveInfo
        end
      end
      return false
    end, Player.HistoryPhase)
    if n == 0 or player:prohibitUse(Fk:cloneCard("slash")) then return false end
    local targets = table.filter(room:getOtherPlayers(player), function(p) return not player:isProhibited(p, Fk:cloneCard("slash")) end)
    if #targets == 0 then return false end
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, n, "#emo__yankui-target:::"..n, self.name, false)
    room:useVirtualCard("slash", nil, player, table.map(tos, Util.Id2PlayerMapper), self.name, true)
  end,
}
moe__zidongying:addSkill(emo__yankui)


Fk:loadTranslationTable{
  ["moe__zidongying"] = "梓鸫荧",

  ["emo__huagui"] = "花鬼",
  [":emo__huagui"] = "锁定技，你的手牌上限为你已损失体力值。",

  ["emo__yankui"] = "艳魁",
  [":emo__yankui"] = "锁定技，弃牌阶段结束时，你视为对一至X名其他角色使用一张【杀】（X为此阶段进入弃牌堆的牌数）。",
  ["#emo__yankui-target"] = "花鬼：视为对至多 %arg 名其他角色使用一张【杀】",
}


local moe__mengnai = General(extension, "moe__mengnai", "moe", 12, 12, General.Female)

local emo__ranxue = fk.CreateTriggerSkill{
  name = "emo__ranxue",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart, fk.CardEffectCancelledOut},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Play
    else
      return target == player and player:hasSkill(self) and data.card.trueName == "slash" and table.contains(data.card.skillNames, self.name)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local tos = table.filter(player.room.alive_players, function(p)
        return not player:isProhibited(p, Fk:cloneCard("slash"))
      end)
      room:useVirtualCard("slash", nil, player, tos, self.name, true)
    else
      local e = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if not e then return end
      local use = e.data[1]
      use.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
    end
  end,
}
moe__mengnai:addSkill(emo__ranxue)

local emo__duanren = fk.CreateTriggerSkill{
  name = "emo__duanren",
  frequency = Skill.Compulsory,
  anim_type = "control",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.card and data.card.trueName == "slash" and (not target.dead)
    and table.find(target:getCardIds("he"), function (id) return Fk:getCardById(id).type == Card.TypeEquip end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    local cards = table.filter(target:getCardIds("he"), function (id) return Fk:getCardById(id).type == Card.TypeEquip end)
    if #cards == 0 then return false end
    local id = table.random(cards)
    room:recastCard({id}, target)
  end,
}

local emo__duanren_distance = fk.CreateDistanceSkill{
  name = "#emo__duanren_distance",
  correct_func = function() return 0 end,
  fixed_func = function(self, from, to)
    if from:hasSkill("emo__duanren") and #to:getCardIds("e") == 0 and from ~= to then
      return 1
    end
  end,
}
emo__duanren:addRelatedSkill(emo__duanren_distance)
moe__mengnai:addSkill(emo__duanren)

local emo__huamo = fk.CreateTriggerSkill{
  name = "emo__huamo",
  anim_type = "negative",
  events = {fk.GameStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local eqipSlots = player:getAvailableEquipSlots()
    if not table.contains(player.sealedSlots, Player.JudgeSlot) then
      table.insert(eqipSlots, Player.JudgeSlot)
    end
    room:abortPlayerArea(player, eqipSlots)
    for i = #room.void, 1, -1 do
      if Fk:getCardById(room.void[i]).name == "kill_demon" then
        local idRemoved = table.remove(room.void, i)
        table.insert(room.draw_pile, math.random(1, #room.draw_pile), idRemoved)
        room:setCardArea(idRemoved, Card.DrawPile, nil)
      end
    end
    room:doBroadcastNotify("UpdateDrawPile", tostring(#room.draw_pile))
  end,
}
moe__mengnai:addSkill(emo__huamo)

Fk:loadTranslationTable{
  ["moe__mengnai"] = "梦奈",

  ["emo__ranxue"] = "染血",
  [":emo__ranxue"] = "锁定技，出牌阶段开始时，视为你对所有角色使用了一张不计入次数的【杀】，此【杀】被任意角色抵消后，令此【杀】失效。",

  ["emo__duanren"] = "断刃",
  [":emo__duanren"] = "锁定技，一名角色受到【杀】造成的伤害后，令其随机重铸一张装备牌。你计算与装备区没有牌的其他角色距离为1。",

  ["emo__huamo"] = "化魔",
  [":emo__huamo"] = "锁定技，游戏开始时，你废除判定区和装备区，将八张【除魔】洗入牌堆。"..
  "<br><font color='grey'><em>除魔：出牌阶段使用，对梦奈造成1点伤害，然后将此牌移出游戏。可重铸。</em></font>",
}

local moe__lingnuoya = General(extension, "moe__lingnuoya", "moe", 4, 4, General.Female)

local emo__huazhu = fk.CreateTriggerSkill{
  name = "emo__huazhu",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2, self.name)
    local pd_targets = table.filter(room:getOtherPlayers(player), function (p) return player:canPindian(p) end)
    if not player:isKongcheng() and #pd_targets > 0 then
      local tos = room:askForChoosePlayers(player, table.map(pd_targets, Util.IdMapper), 1, 2, "#emo__huazhu_pd", self.name, false)
      if #tos > 0 then
        tos = table.map(tos, Util.Id2PlayerMapper)
        local pindian = player:pindian(tos, self.name)
        local sum = 0
        local max_num = 0
        local damageTo
        for _, to in ipairs(tos) do
          local result = pindian.results[to.id]
          if result and result.toCard then
            local num = result.toCard.number
            sum = sum + num
            max_num = math.max(max_num, num)
            if num == max_num then
              damageTo = to
            end
            local winner = pindian.results[to.id].winner
            if winner == player and not player.dead then
              player:drawCards(1, self.name)
            end
          end
        end
        if sum > 10 and damageTo and not damageTo.dead then
          room:damage{ from = player, to = damageTo, damage = 1, skillName = self.name , damageType = fk.FireDamage }
        end
      end
    end
    local throw = room:askForDiscard(player, 2, 2, true, self.name, false, ".", "#emo__huazhu-discard")
    if #throw == 0 or player.dead then return false end

    local basic = #table.filter(throw, function (id) return Fk:getCardById(id).type == Card.TypeBasic end)
    if basic == 0 then
      room:addPlayerMark(player, "emo__huazhu_basic-phase")
    elseif basic == #throw then
      local slash = Fk:cloneCard("slash")
      local max_num = slash.skill:getMaxTargetNum(player, slash)
      local slash_targets = {}
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if not player:isProhibited(p, slash) then
          table.insert(slash_targets, p.id)
        end
      end
      if #slash_targets > 0 and max_num > 0 then
        local tos = room:askForChoosePlayers(player, slash_targets, 1, max_num+1, "#emo__huazhu-slash", self.name, false)
        if #tos > 0 then
          room:useVirtualCard("slash", nil, player, table.map(tos, Util.Id2PlayerMapper), self.name, true)
        end
      end
    end
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("emo__huazhu_basic-phase") > 0 and data.card.type == Card.TypeBasic
  end,
  on_refresh = function(self, event, target, player, data)
    data.additionalEffect = (data.additionalEffect or 0) + 1
  end,
}

moe__lingnuoya:addSkill(emo__huazhu)


Fk:loadTranslationTable{
  ["moe__lingnuoya"] = "凌诺雅",

  ["emo__huazhu"] = "花主",
  [":emo__huazhu"] = "出牌阶段开始时，你可以摸两张牌，然后用一张手牌与一至两名其他角色同时拼点，你每赢一次便摸一张牌，若其他角色的拼点牌点数之和大于10，你对其中点数较大的一名角色造成1点火焰伤害。最后你弃置两张牌，若你弃置的牌均为：基本牌，你视为使用一张无距离限制、不计入次数且目标上限+1的【杀】；非基本牌，本阶段你使用基本牌额外结算一次。",
  ["emo__huazhu_pd"] = "花主",
  ["#emo__huazhu_pd"] = "花主：用一张手牌与一至两名其他角色同时拼点，每赢一次便摸一张牌",
  ["#emo__huazhu-slash"] = "花主：你视为使用一张无距离限制、不计入次数且目标上限+1的【杀】",
  ["#emo__huazhu-discard"] = "花主：弃置两张牌，若均为基本牌或非基本牌，执行额外效果",
}

local moe__aiweina = General(extension, "moe__aiweina", "moe", 4, 4, General.Female)

local emo__shenghu = fk.CreateTriggerSkill{
  name = "emo__shenghu",
  anim_type = "defensive",
  events = {fk.GameStart , fk.TurnStart , fk.DamageCaused , fk.DamageInflicted , fk.Death , fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    local ShenghuTarget = table.find(player.room.alive_players, function (p) return p:getMark("@@emo__shenghu") > 0 end)
    if event == fk.GameStart or event == fk.TurnStart then
      return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
      and (target == player or event == fk.GameStart)
    elseif event == fk.DamageCaused then
      return player:hasSkill(self) and target == player and ShenghuTarget
      and data.card and data.card.trueName == "slash" and data.to:getMark("@@emo__shenghu") == 0
    elseif event == fk.DamageInflicted then
      return player:hasSkill(self) and target:getMark("@@emo__shenghu") > 0 and not (data.card and data.card.trueName == "slash")
    elseif event == fk.Death then
      return player:hasSkill(self) and target:getMark("@@emo__shenghu") > 0
    else
      return player:hasSkill(self) and target == player and player:getMark("emo__shenghu_revenge") > 0 and data.card.trueName == "slash"
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart or event == fk.TurnStart then
      local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#emo__shenghu-choose", self.name, true)
      if #tos > 0 then
        self.cost_data = tos[1]
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart or event == fk.TurnStart then
      local to = room:getPlayerById(self.cost_data)
      room:addPlayerMark(to, "@@emo__shenghu")
      local cards = room:getCardsFromPileByRule("slash")
      if #cards > 0 then room:obtainCard(player, cards[1], true, fk.ReasonPrey) end
    elseif event == fk.DamageCaused then
      data.damage = data.damage + 1
    elseif event == fk.DamageInflicted then
      return true
    elseif event == fk.Death then
      room:changeMaxHp(player, -1)
      room:addPlayerMark(player, "emo__shenghu_revenge")
    else
      data.disresponsive = true
    end
  end,

  refresh_events = {fk.Deathed, fk.EventLoseSkill},
  can_refresh = function(self, event, target, player, data)
    return target == player and (player:hasSkill(self, true, true) or data == self)
    and not table.find(player.room.alive_players, function (p) return p:hasSkill(self, true) end)
  end,
  on_refresh = function(self, event, target, player, data)
    for _, p in ipairs(player.room.alive_players) do
      player.room:setPlayerMark(p, "@@emo__shenghu", 0)
    end
  end,
}

moe__aiweina:addSkill(emo__shenghu)

local emo__bingjia = fk.CreateTriggerSkill{
  name ="emo__bingjia",
  events = {fk.EventPhaseStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.shield == 0 and player.hp == 1 and player.phase == Player.Finish
  end,
  on_use = function(self, event, target, player, data)
    player.room:changeShield(player, 1)
  end,
}
moe__aiweina:addSkill(emo__bingjia)

Fk:loadTranslationTable{
  ["moe__aiweina"] = "艾维娜",

  ["emo__shenghu"] = "圣护",
  [":emo__shenghu"] = "①游戏开始时或回合开始时，若你未发动此技能，你可以令一名其他角色获得“圣护”标记，然后你摸一张【杀】。<br>"..
  "②拥有“圣护”标记的角色存活时，你使用【杀】对其以外的角色造成伤害+1，且防止其受到【杀】以外的伤害。<br>"..
  "③拥有“圣护”标记的角色死亡时，你扣减1点体力上限，你使用【杀】无法响应。",
  ["#emo__shenghu-choose"] = "圣护：令一名其他角色获得“圣护”标记（建议选队友）",
  ["@@emo__shenghu"] = "圣护",

  ["emo__bingjia"] = "冰甲",
  [":emo__bingjia"] = "锁定技，结束阶段开始时，若你体力值为1且没有护甲，你获得1点护甲。",
}

local moe__xifu = General(extension, "moe__xifu", "moe", 4, 4, General.Female)

local emo__ciren = fk.CreateTriggerSkill{
  name = "emo__ciren",
  events = {fk.EventPhaseStart},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Start then
      return table.find(player:getCardIds("he"), function (id) return Fk:getCardById(id).trueName == "mithril_dagger" end) == nil
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cardId = MoeFunc.getDerivedCard(room, "mithril_dagger")
    if cardId == nil then return false end
    local from = room:getCardOwner(cardId)
    room:obtainCard(player, cardId, true, fk.ReasonPrey, player.id, self.name)
    if not player.dead and table.contains(player:getCardIds("h"), cardId) then
      Fk:filterCard(cardId, player)
      local card = Fk:getCardById(cardId)
      if card.name == "mithril_dagger" and player:canUseTo(card, player) then
        room:useCard{from = player.id, tos = {{player.id}}, card = card}
      end
    end
    if from and not from.dead and not player.dead and from ~= player
    and room:askForSkillInvoke(player, self.name, nil, "#emo__ciren-draw:"..from.id) then
      room:doIndicate(player.id, {from.id})
      from:drawCards(2, self.name)
    end
  end,
}
moe__xifu:addSkill(emo__ciren)

local emo__xunzhan = fk.CreateTriggerSkill{
  name = "emo__xunzhan",
  events = {fk.EventPhaseStart},
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(self) and target.phase == Player.Play and not target.dead then
      return (not target:isKongcheng()) or (not player:isNude())
    end
  end,
  on_cost = function (self, event, target, player, data)
    local _,dat = player.room:askForUseActiveSkill(player, "emo__xunzhan_active", "#emo__xunzhan-ask:"..target.id,
    true, {emo__xunzhan_to = target.id})
    if dat then
      self.cost_data = {choice = dat.interaction, tos = {target.id}, cards = dat.cards}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cardId
    if self.cost_data.choice == "emo__xunzhan_throw" then
      cardId = room:askForCardChosen(player, target, "h", self.name)
      room:throwCard(cardId, self.name, target, player)
    else
      cardId = self.cost_data.cards[1]
      room:useVirtualCard("slash", self.cost_data.cards, player, target, self.name, true)
    end
    local inhand = table.contains(target:getCardIds("h"), cardId)
    if not target.dead and (room:getCardArea(cardId) == Card.DiscardPile or inhand) then
      if inhand then
        Fk:filterCard(cardId, target)
      end
      local card = Fk:getCardById(cardId)
      if card.type == Card.TypeEquip then
        if target:getAvailableEquipSlots(card.sub_type) and not target:prohibitUse(card) then
          room:useCard{from = target.id, tos = {{target.id}}, card = card}
        end
      elseif card.trueName == "slash" then
        local extra_data = {extraUse = false}
        if not inhand then
          extra_data.expand_pile = {cardId}
        end
        U.askForUseRealCard(room, target, {cardId}, ".", self.name, "#emo__xunzhan_slash", extra_data, false, false)
      end
    end
  end,
}

local emo__xunzhan_active = fk.CreateActiveSkill{
  name = "emo__xunzhan_active",
  card_num = 1,
  target_num = 0,
  interaction = function(self)
    local all_choices = {"emo__xunzhan_throw", "emo__xunzhan_slash"}
    local choices = {}
    local to = Fk:currentRoom():getPlayerById(self.emo__xunzhan_to)
    if to and not to:isKongcheng() then
      table.insert(choices, "emo__xunzhan_throw")
    end
    if not Self:isNude() then
      table.insert(choices, "emo__xunzhan_slash")
    end
    return UI.ComboBox { choices = choices, all_choices = all_choices }
  end,
  card_filter = function(self, to_select, selected)
    local choice = self.interaction.data
    if choice == "emo__xunzhan_slash" then
      if #selected ~= 0 then return false end
      local to = Fk:currentRoom():getPlayerById(self.emo__xunzhan_to)
      if not to then return false end
      local c = Fk:cloneCard("slash")
      c.skillName = "emo__xunzhan"
      c:addSubcard(to_select)
      return Self:canUseTo(c, to, {bypass_distances = true, bypass_times = true})
    elseif choice == "emo__xunzhan_throw" then
      return false
    end
  end,
  feasible = function (self, selected, selected_cards)
    local choice = self.interaction.data
    if choice == "emo__xunzhan_slash" then
      return #selected_cards == 1
    elseif choice == "emo__xunzhan_throw" then
      return #selected_cards == 0
    end
  end,
}
Fk:addSkill(emo__xunzhan_active)

moe__xifu:addSkill(emo__xunzhan)

Fk:loadTranslationTable{
  ["moe__xifu"] = "希芙",
  ["#moe__xifu"] = "圣殉者",

  ["emo__ciren"] = "赐刃",
  [":emo__ciren"] = "准备阶段，若你没有【秘银短匕】，你获得并使用之，若你从其他角色区域内获得，你可以令其摸两张牌。",
  ["#emo__ciren-draw"] = "赐刃：你可以令 %src 摸两张牌",

  ["emo__xunzhan"] = "殉战",
  [":emo__xunzhan"] = "其他角色的出牌阶段开始时，你可以弃置其一张手牌，或将一张牌当【杀】对其使用，然后若此牌为装备牌或【杀】，令其使用之。",
  ["#emo__xunzhan-ask"] = "殉战：你可以弃置 %src 的手牌，或将一张牌当【杀】对其使用",
  ["emo__xunzhan_throw"] = "弃置其手牌",
  ["emo__xunzhan_slash"] = "一张牌当【杀】",
  ["emo__xunzhan_active"] = "殉战",
  ["#emo__xunzhan_slash"] = "殉战：你须使用这张【杀】！",
}

local moe__anya = General(extension, "moe__anya", "moe", 3, 3, General.Female)

local emo__zhishui = fk.CreateTriggerSkill{
  name = "emo__zhishui",
  anim_type = "support",
  events = {fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) 
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "#emo__zhishui-choose"
    local previous = player:getMark("emo__zhishui_target")
    if previous ~= 0 then
      prompt = "#emo__zhishui_previous-choose:"..previous
    end
    local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, prompt, self.name, true)
    if #tos > 0 then
      self.cost_data = tos[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local previous = room:getPlayerById(player:getMark("emo__zhishui_target"))
    room:addPlayerMark(to, "@@emo__zhishui-round")
    room:setPlayerMark(player, "emo__zhishui_target", to.id)
    if previous and previous == to then
      room:loseHp(player, 1, self.name)
    end
  end,
}

local emo__zhishui_delay = fk.CreateTriggerSkill{
  name = "#emo__zhishui_delay",
  anim_type = "defensive",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target:getMark("@@emo__zhishui-round") > 0 and player == target
    and (data.damage > 1 or player:getMark("emo__zhishui_invoked-round") == 0)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.damage > 1 then
      data.damage = data.damage - 1
    end
    if player:getMark("emo__zhishui_invoked-round") == 0 then
      room:setPlayerMark(player, "emo__zhishui_invoked-round", 1)
      data.damage = data.damage - 1
    end
  end,
}
emo__zhishui:addRelatedSkill(emo__zhishui_delay)
moe__anya:addSkill(emo__zhishui)

local emo__lingfeng = fk.CreateTriggerSkill{
  name = "emo__lingfeng",
  anim_type = "control",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    local currentEvent = player.room.logic:getCurrentEvent()
    local turnEvent = currentEvent:findParent(GameEvent.Turn)
    local suitCheck = function (suit)
      if turnEvent == nil then return false end
      return #player.room.logic:getEventsByRule(GameEvent.MoveCards, 1, function (e)
        if e.id >= currentEvent.id then return false end
        for _, move in ipairs(e.data) do
          if (move.toArea == Card.DiscardPile or move.toArea == Card.Processing) then
            for _, info in ipairs(move.moveInfo) do
              if Fk:getCardById(info.cardId):getSuitString() == suit then
                return true
              end
            end
          end
        end
      end, turnEvent.id) == 0
    end
    local suits = {}
    for _, move in ipairs(data) do
      if move.from == player.id and (move.toArea == Card.DiscardPile or move.toArea == Card.Processing) then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
            table.insert(suits, Fk:getCardById(info.cardId):getSuitString())
          end
        end
      end
    end
    if #suits == 0 then return false end
    suits = table.filter(suits, suitCheck)
    if #suits > 0 then
      self.cost_data = suits
      return true
    end
  end,
  on_trigger = function (self, event, target, player, data)
    local suits = table.simpleClone(self.cost_data)
    for _, suit in ipairs(suits) do
      if not player:hasSkill(self) then return end
      self:doCost(event, player, player, suit)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
     "#emo__lingfeng-choose:::log_"..data, self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos, suit = data}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local suit = self.cost_data.suit
    local ids = room:getCardsFromPileByRule(".|.|"..suit)
    if #ids > 0 then
      room:obtainCard(to, ids, true, fk.ReasonJustMove, player.id, self.name)
    end
  end,
}
moe__anya:addSkill(emo__lingfeng)

Fk:loadTranslationTable{
  ["moe__anya"] = "安雅",

  ["emo__zhishui"] = "止水",
  [":emo__zhishui"] = "每轮开始时，你可以选择一名角色，其本轮受到的首次伤害和大于1点的伤害-1。若你选择的角色与上次相同，你失去1点体力。",
  ["#emo__zhishui-choose"] = "止水：你可选择一名角色，其本轮受到的首次伤害和大于1点的伤害-1",
  ["#emo__zhishui_previous-choose"] = "止水：令一名角色本轮受到的首次伤害和大于1点的伤害-1，若选择 %src 你失去1点体力",
  ["@@emo__zhishui-round"] = "止水",
  ["#emo__zhishui_delay"] = "止水",

  ["emo__lingfeng"] = "聆风",
  [":emo__lingfeng"] = "每当你失去一张牌时，若此花色的牌本回合首次进入处理区或弃牌堆，你可令一名角色从牌堆随机获得一张此花色的牌。",
  ["#emo__lingfeng-choose"] = "聆风：你可令一名角色从牌堆随机获得一张 %arg 牌",
}

local moe__victoria = General(extension, "moe__victoria", "moe", 3, 3, General.Female)

local emo__lianshang = fk.CreateTriggerSkill{
  name = "emo__lianshang",
  anim_type = "control",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target and (not target.dead) and player:hasSkill(self) and (not player:isKongcheng()) and data.from
    and data.from ~= player and (not data.from.dead) and player:canPindian(data.from)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#emo__lianshang-invoke:"..data.from.id..":"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local pindian = player:pindian({data.from}, self.name)
    local winner = pindian.results[data.from.id].winner
    if winner and winner == player then
      if not target.dead and target:isWounded() then
        room:recover { num = 1, skillName = self.name, who = target, recoverBy = player}
      end
    else
      local ids = {}
      for _, card in ipairs({pindian.fromCard, pindian.results[data.from.id].toCard}) do
        if room:getCardArea(card) == Card.DiscardPile then
          table.insertIfNeed(ids, card:getEffectiveId())
        end
      end
      if #ids > 0 and not player.dead then
        room:moveCards({
          ids = ids,
          to = target.id,
          toArea = Player.Hand,
          moveReason = fk.ReasonPrey,
          proposer = player.id,
          skillName = self.name,
        })
      end
    end
    if not (data.card and data.card.trueName == "slash") and not player.dead then
      player:drawCards(1, self.name)
    end
  end,
}
moe__victoria:addSkill(emo__lianshang)

local emo__jieli = fk.CreateActiveSkill{
  name = "emo__jieli",
  anim_type = "support",
  prompt = "#emo__jieli-prompt",
  can_use = function(self, player)
    return player:getMark("emo__jieli-phase") == 0 and
    player:usedSkillTimes(self.name, Player.HistoryPhase) < #Fk:currentRoom().alive_players
  end,
  card_num = 1,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).trueName == "slash"
  end,
  target_num = 1,
  target_filter = function(self, to_select, selected, cards)
    return #selected == 0 and to_select ~= Self.id and #cards == 1
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:recastCard(effect.cards, player, self.name)
    local to = room:getPlayerById(effect.tos[1])
    if player.dead then return end
    if to.dead or to:isNude() then
      room:addPlayerMark(player, "emo__jieli-phase")
      return
    end
    local cards = room:askForCard(to, 1, 1, false, self.name, true, "slash", "#emo__jieli-discard:"..player.id)
    if #cards > 0 then
      room:recastCard(cards, player, self.name)
      if not player.dead then
        player:drawCards(1, self.name)
      end
      if not to.dead then
        to:drawCards(1, self.name)
      end
    else
      room:addPlayerMark(player, "emo__jieli-phase")
      local cid = room:askForCardChosen(player, to, "he", self.name)
      room:moveCardTo(cid, Player.Hand, player, fk.ReasonPrey, self.name, nil, false, player.id)
    end
  end,
}
moe__victoria:addSkill(emo__jieli)

local emo__anqin = fk.CreateMaxCardsSkill{
  name = "emo__anqin$",
  exclude_from = function(self, player, card)
    if card and (card.trueName == "jink" or card.trueName == "peach") then
      if player.kingdom == "moe" then
        for _, lord in ipairs(Fk:currentRoom().alive_players) do
          if lord:hasSkill(self) and lord.role == "lord" and table.find(Fk:currentRoom().alive_players, function(p) return p ~= lord and p.kingdom == "moe" end) then
            return true
          end
        end
      end
    end
  end,
}
moe__victoria:addSkill(emo__anqin)

Fk:loadTranslationTable{
  ["moe__victoria"] = "维多利亚",

  ["emo__lianshang"] = "怜伤",
  [":emo__lianshang"] = "一名角色受到伤害后，若其仍存活，你可以与伤害来源拼点：若你赢，你令该角色回复1点体力；若你没赢，该角色获得两张拼点牌。若不为【杀】造成的伤害，你摸一张牌。",
  ["#emo__lianshang-invoke"] = "怜伤：你可与 %src 拼点：若你赢，你令 %dest 回复1点体力；若你没赢，%dest 获得两张拼点牌",

  ["emo__jieli"] = "戒戾",
  [":emo__jieli"] = "出牌阶段限X次，你可以重铸一张【杀】并令一名其他角色选一项：1.重铸一张【杀】，与你各摸一张牌；2.你获得其一张牌，此阶段〖戒戾〗无效（X为存活角色数）。",
  ["#emo__jieli-discard"] = "戒戾:1.重铸一张【杀】，与 %src 各摸一张牌；2.%src 获得你一张牌",
  ["#emo__jieli-prompt"] = "戒戾:重铸一张【杀】并选择一名其他角色",

  ["emo__anqin"] = "安寝",
  [":emo__anqin"] = "主公技，锁定技，若其他萌势力角色存活，你与其的【闪】和【桃】不计入手牌上限。",
}

local moe__taolesi = General(extension, "moe__taolesi", "moe", 3, 3, General.Female)

local emo__longque = fk.CreateTriggerSkill{
  name = "emo__longque",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    local n = 0
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          local card = Fk:getCardById(info.cardId)
          if card.type == Card.TypeTrick and (card.multiple_targets or card.sub_type == Card.SubtypeDelayedTrick) then
            n = n + 1
          end
        end
      end
    end
    if n > 0 then
      self.cost_data = n
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(self.cost_data, self.name)
  end,
}
local emo__longque_prohibit = fk.CreateProhibitSkill{
  name = "#emo__longque_prohibit",
  frequency = Skill.Compulsory,
  is_prohibited = function (self, from, to, card)
    return to:hasSkill(self) and card and card.type == Card.TypeTrick
    and (card.multiple_targets or card.sub_type == Card.SubtypeDelayedTrick)
  end,
}
emo__longque:addRelatedSkill(emo__longque_prohibit)

moe__taolesi:addSkill(emo__longque)


local emo__suoxin = fk.CreateTriggerSkill{
  name = "emo__suoxin",
  anim_type = "control",
  events = {fk.CardUseFinished, fk.Damaged, fk.Death},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      return player:hasSkill(self) and target ~= player and not target.dead and data.card:isVirtual() and data.card.is_damage_card
    elseif event == fk.Damaged then
      return player:hasSkill(self) and target ~= player and not target.dead and data.damage > 1 and target.faceup
    else
      if player:hasSkill(self,false,true) and target == player and data.damage and data.damage.from then
        local from = data.damage.from
        return from:isAlive() and table.contains(player:getTableMark("emo__suoxin_target"), from.id)
        and table.find(from:getAvailableEquipSlots(), function(slot) 
          return #from:getEquipments(Util.convertSubtypeAndEquipSlot(slot)) == 0 
        end)
      end 
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      return player.room:askForSkillInvoke(player, self.name, nil, "#emo__suoxin-losehp:"..target.id)
    elseif event == fk.Damaged then
      return player.room:askForSkillInvoke(player, self.name, nil, "#emo__suoxin-turnover:"..target.id)
    else
      return player.room:askForSkillInvoke(player, self.name, nil, "#emo__suoxin-abort:"..data.damage.from.id)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Death then
      local from = data.damage.from
      room:doIndicate(player.id, {from.id})
      local slots = {}
      for _, slot in ipairs(from:getAvailableEquipSlots()) do
        local type = Util.convertSubtypeAndEquipSlot(slot)
        if #from:getEquipments(type) == 0 then
          table.insert(slots, slot)
        end
      end
      room:abortPlayerArea(from, slots)
    else
      room:doIndicate(player.id, {target.id})
      local mark = player:getTableMark("emo__suoxin_target")
      if table.insertIfNeed(mark, target.id) then
        room:setPlayerMark(player, "emo__suoxin_target", mark)
      end
      if event == fk.CardUseFinished then
        room:loseHp(target, 1, self.name)
      else
        target:turnOver()
      end
    end
  end,
}
moe__taolesi:addSkill(emo__suoxin)

Fk:loadTranslationTable{
  ["moe__taolesi"] = "桃乐丝",
  
  ["emo__longque"] = "笼雀",
  [":emo__longque"] = "锁定技，延时锦囊牌和多目标锦囊不能指定你为目标；每当一张延时锦囊牌或多目标锦囊进入弃牌堆后，你摸一张牌。",
  ["#emo__longque_prohibit"] = "笼雀",

  ["emo__suoxin"] = "锁心",
  [":emo__suoxin"] = "①每当一名其他角色使用的转化或虚拟的伤害牌结算后，你可以令其失去一点体力。<br>②每当一名其他角色受到大于1点的伤害后，你可以令其翻至背面。<br>③当你死亡时，若你对伤害来源发动过〖锁心〗，你可以令其废除所有空置的装备栏。",

  ["#emo__suoxin-losehp"] = "锁心：你可以令 %src 失去一点体力",
  ["#emo__suoxin-turnover"] = "锁心：你可以令 %src 翻至背面",
  ["#emo__suoxin-abort"] = "锁心：你可以令 %src 废除空置的装备栏",
}



local moe__yeling = General(extension, "moe__yeling", "moe", 3, 3, General.Female)

local emo__xuewu = fk.CreateActiveSkill{
  name = "emo__xuewu",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  prompt = "#emo__xuewu-prompt",
  can_use = function(self, player)
    return player:getMark("emo__xuewu_fail-phase") == 0 and player:canUse(Fk:cloneCard("slash"))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local cards = {}
    for i, id in ipairs(room.draw_pile) do
      if i > 3 then break end
      if Fk:getCardById(id).trueName == "slash" then
        table.insert(cards, id)
      end
    end
    for _, p in ipairs(room:getOtherPlayers(player)) do
      for _, id in ipairs(p:getCardIds("h")) do
        if Fk:getCardById(id).trueName == "slash" then
          table.insert(cards, id)
        end
      end
    end
    if #cards > 0 then
      local cid = table.random(cards)
      local owner = room.owner_map[cid]
      local from = owner and room:getPlayerById(owner) or player
      from:showCards({cid})
      local slash = Fk:getCardById(cid)
      local max_num = slash.skill:getMaxTargetNum(player, slash)
      local targets = table.filter(room.alive_players, function (p)
        return player:canUseTo(slash, p)
      end)
      if max_num > 0 and #targets > 0 then
        local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1,
        "#emo__xuewu-choose:::"..slash:toLogString(), self.name, false)
        room:useCard{
          from = player.id,
          tos = table.map(tos, function(p) return {p} end),
          card = slash,
          extra_data = {emo__xuewu_from = owner or 0}
        }
        return nil
      end
    end
    room:setPlayerMark(player, "emo__xuewu_fail-phase", 1)
  end,
}

local emo__xuewu_trigger = fk.CreateTriggerSkill{
  name = "#emo__xuewu_trigger",
  -- 用于修改杀的伤害来源
  refresh_events = {fk.PreDamage},
  can_refresh = function(self, event, target, player, data)
    local e = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
    if e then
      return (e.data[1].extra_data or {}).emo__xuewu_from
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local e = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
    if e then
      local owner = e.data[1].extra_data.emo__xuewu_from
      if owner == 0 then
        data.from = nil
      else
        data.from = room:getPlayerById(owner)
      end
    end
  end,
}
emo__xuewu:addRelatedSkill(emo__xuewu_trigger)
moe__yeling:addSkill(emo__xuewu)

local emo__shayu = fk.CreateTriggerSkill{
  name = "emo__shayu",
  anim_type = "defensive",
  events = {fk.Damaged},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self) and not player:isNude() and player.phase == Player.NotActive
  end,
  on_cost = function (self, event, target, player, data)
    local cards = player.room:askForDiscard(player, 1, #player:getCardIds("he"), true, self.name, true, ".", "#emo__shayu-card", true)
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = self.cost_data
    local add = (not data.card) or table.every(cards, function (id)
      return Fk:getCardById(id).color ~= data.card.color
    end)
    room:throwCard(cards, self.name, player, player)
    if player.dead then return end
    player:drawCards(#cards + 1, self.name)
    if player.dead then return end
    if add then
      room:addPlayerMark(player, "@emo__shayu")
    end
  end,

  refresh_events = {fk.TurnEnd},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@emo__shayu") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@emo__shayu", 0)
  end,
}
local emo__shayu_targetmod = fk.CreateTargetModSkill{
  name = "#emo__shayu_targetmod",
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      return player:getMark("@emo__shayu")
    end
  end,
}
emo__shayu:addRelatedSkill(emo__shayu_targetmod)
moe__yeling:addSkill(emo__shayu)

Fk:loadTranslationTable{
  ["moe__yeling"] = "夜聆",

  ["emo__xuewu"] = "血舞",
  [":emo__xuewu"] = "出牌阶段，若你可以使用【杀】，你可以发动此技能：若其他角色手牌中或牌堆顶三张牌中有【杀】，你随机展示其中一张【杀】并使用之（此【杀】造成的伤害来源视为拥有此【杀】的角色，若为牌堆的【杀】视为无伤害来源），若这些牌中没有【杀】或你未使用之，本技能于此阶段失效。",
  ["#emo__xuewu_trigger"] = "血舞",
  ["#emo__xuewu-choose"] = "血舞：请选择你使用%arg的目标",
  ["#emo__xuewu-prompt"] = "血舞：若其他角色手牌中或牌堆顶三张牌中有【杀】，你可使用之，若无，本技能此阶段失效",

  ["emo__shayu"] = "铩羽",
  [":emo__shayu"] = "每当你于回合外受到伤害后，你可以弃置至少一张牌，摸X张牌（X为弃置牌数+1），若没有造成伤害的牌，或造成伤害的牌与你弃置的牌颜色均不同，你使用【杀】次数上限+1直到你下回合结束。",
  ["#emo__shayu-card"] = "铩羽：弃置至少一张牌，摸等量+1张牌",
  ["@emo__shayu"] = "铩羽",
}

local moe__dianna = General(extension, "moe__dianna", "moe", 4, 4, General.Female)

local emo__gongshou = fk.CreateTriggerSkill{
  name = "emo__gongshou",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player and player.phase == Player.Start then
      return table.every(player.room.alive_players, function(p) return p:getMark("@@emo__gongshou") == 0 end)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local tos = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#emo__gongshou-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = tos[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    room:setPlayerMark(to, "@@emo__gongshou", 1)
  end,
}
local emo__gongshou_attackrange = fk.CreateAttackRangeSkill{
  name = "#emo__gongshou_attackrange",
  correct_func = function (self, from, to)
    if from:hasSkill("emo__gongshou") then
      for _, p in ipairs(Fk:currentRoom().alive_players) do
        if p:getMark("@@emo__gongshou") > 0 then
          local weapon = p:getEquipment(Card.SubtypeWeapon)
          if weapon then
            return Fk:getCardById(weapon).attack_range or 0
          end
        end
      end
    end
  end,
}
emo__gongshou:addRelatedSkill(emo__gongshou_attackrange)

moe__dianna:addSkill(emo__gongshou)


local emo__youtian = fk.CreateActiveSkill{
  name = "emo__youtian",
  anim_type = "offensive",
  card_filter = Util.FalseFunc,
  prompt = "#emo__youtian-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < #Fk:currentRoom().alive_players and player:getAttackRange() > 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local targets = table.filter(room.alive_players, function(p) return player:inMyAttackRange(p) end)
    player:drawCards(1, self.name)
    room:addPlayerMark(player, "emo__youtian-phase", 1)
    if player.dead then return end
    targets = table.filter(targets, function (p) return not player:inMyAttackRange(p) end)
    if #targets > 0 then
      local use = room:askForUseCard(player, "slash", "slash", "#emo__youtian-slash", true,
      {exclusive_targets = table.map(targets, Util.IdMapper) , bypass_distances = true })
      if use then
        use.extraUse = true
        room:useCard(use)
      end
    end
  end,
}
local emo__youtian_attackrange = fk.CreateAttackRangeSkill{
  name = "#emo__youtian_attackrange",
  correct_func = function (self, from, to)
    return - from:getMark("emo__youtian-phase")
  end,
}
emo__gongshou:addRelatedSkill(emo__youtian_attackrange)

moe__dianna:addSkill(emo__youtian)

Fk:loadTranslationTable{
  ["moe__dianna"] = "狄安娜",

  ["emo__gongshou"] = "共狩",
  [":emo__gongshou"] = "准备阶段开始时，若没有角色拥有“狩”标记，你可以令一名其他角色获得“狩”标记，你的攻击范围+X（X为该角色装备区武器牌的攻击范围）。",
  ["@@emo__gongshou"] = "狩",
  ["#emo__gongshou-choose"] = "共狩：令一名其他角色获得“狩”标记，你获得其武器的攻击范围",

  ["emo__youtian"] = "游畋",
  [":emo__youtian"] = "出牌阶段限X次，若你攻击范围大于0，你可以摸一张牌并令本阶段攻击范围-1，若有角色因此脱离你的攻击范围，你可以对其中一名角色使用一张不计入次数的【杀】（X为存活角色数）。",
  ["#emo__youtian-slash"] = "游畋：你可以对其中一名角色使用【杀】",
  ["#emo__youtian-prompt"] = "游畋：你可以摸一张牌并令本阶段攻击范围-1",
}














--[[

Fk:loadTranslationTable{
  [""] = "",

  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
}

--]]


return extension

